{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19.21\n"
     ]
    }
   ],
   "source": [
    "# 1. 读取文件\n",
    "f = open(\"d:\\\\sensor.txt\",\"r\",encoding=\"utf-8\")\n",
    "\n",
    "# 2. 取出数据\n",
    "ls = []\n",
    "# 读取一行\n",
    "s = f.readline()\n",
    "while s:\n",
    "    # 取出温度 放入一个温度列表\n",
    "    ls.append(float(s.split(\" \")[2]))\n",
    "    # 读取下一行\n",
    "    s = f.readline()\n",
    "# 求总和/数量\n",
    "print( \"{:.2f}\".format(sum(ls)/len(ls)))\n",
    "\n",
    "# 3. 关闭文件\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
